#include "MenuManager.h"
#include <QDebug>
#include "commonstr.h"
#include "CSkipButton.h"
#include "CExpandButton.h"
#include "CSwitchButton.h"
#include "ContainsExitForm.h"
#include "LeafForm.h"
#include "CTextElement.h"
#include "CIconElement.h"
#include "MainMenuForm.h"
#include "UIElementOtherInfo.hpp"
#include "SecondMenuForm.h"
#include "SwitchLElement.h"
#include "AutoSwitchButton.h"
#include "DiyMenuForm.h"
#include "notifyevent.h"
#include <QVBoxLayout>
#define CHECK_FORM(X)                                   \
 if(_stackForms->count()==0){            \
    return;                                             \
 }                                                      \
 ElementForm* form =                                    \
dynamic_cast<ElementForm*>(_stackForms->currentWidget());\
 if (form == nullptr) {                                 \
     return;                                            \
 }                                                      \
 form->##X()

MenuManager::MenuManager(QWidget* parent) :
	TransparentForm(parent), KeyEvent()
{
	initUI();
	initConnect();
}

void MenuManager::initUI()
{
	QVBoxLayout* layout = new QVBoxLayout(this);
	_stackForms = new QStackedWidget(this);
	layout->addWidget(_stackForms);
	addMenuForm(new DiyMenuForm(nullptr));
	addMenuForm(new MainMenuForm(nullptr, 5, 73, 14));
	addMenuForm(new MainMenuForm(nullptr, 5, 73, 14));
	addMenuForm(new SecondMenuForm(nullptr, 4, 127, 14));
	addMenuForm(new SecondMenuForm(nullptr, 4, 127, 14));
	addMenuForm(new SecondMenuForm(nullptr, 4, 127, 14));
	addMenuForm(new SecondMenuForm(nullptr, 4, 127, 14));
	addMenuForm(new LeafForm(nullptr));

	
}

void MenuManager::initConnect()
{
	NotifyEvent::add(NOTIFY_MENU_MANAGER_EVENT_TYPE, &MenuManager::notifyEvent, this);
}

void MenuManager::setMenuFormIndex(const int& index)
{
	if (index < 0 || index >= _stackForms->count()) {
		return;
	}
	int lastIndex = _stackForms->currentIndex();
	_stackForms->setCurrentIndex(index);
	ElementForm* form = dynamic_cast<ElementForm*>(_stackForms->currentWidget());
	if (form == nullptr) {
		return;
	}
	switch (index) {
	case DIY_MENU_FORM_INDEX: 
	{
		form->setElements(buildDiyMenu());
	}
		break;
	case MAIN_MENU_FORM_INDEX:
	case SHORT_MENU_FORM_INDEX: 
	case SECOND_MENU_FORM_INDEX:
	case THIRD_MENU_FORM_INDEX:
	case FOURTH_MENU_FORM_INDEX:
	case FIVETH_MENU_FORM_INDEX:
	case LEAF_MENU_FORM_INDEX:
	{
		auto lastForm = dynamic_cast<ElementForm*>(_stackForms->widget(lastIndex));
		if (lastForm != nullptr) {
			form->setParent(lastForm);
		}
	}

	break;
	default:
		break;
	}
	QWidget::show();
}

bool MenuManager::isHideMenuForm() const
{
	return _stackForms->isHidden();
}

void MenuManager::notify(int type, void* data)
{
	switch (type)
	{
	case MENU:
	{
		auto form = dynamic_cast<MainMenuForm*>(_stackForms->widget(static_cast<int>(MAIN_MENU_FORM_INDEX)));
		form->setElements(buildMainMenu());
		setMenuFormIndex(MAIN_MENU_FORM_INDEX);
	}
		break;
	default:
		break;
	}

}

void MenuManager::notifyEvent(int type, void* data, void* context)
{
	CONVERT_PTR_TO_CLASS(context, MenuManager)
		if (ptr) {
			ptr->notify(type, data);
		}
}

QList<UIElement*> MenuManager::buildDiyMenu()
{
	QList<UIElement*> elements;
	QString iPathPerfix = ":/UI/icon/diy";
	UIElement* element = nullptr;
	for (int i = DIY_SLIDE_MENU_MENU; i < DIY_SLIDE_MENU_ROUGH_RANGING; i++) {
		switch (i) {
		case DIY_SLIDE_MENU_MENU:
		{
			QList<QString> list;
			QString cmdKey = "Menu";
			element = new AutoSwitchButton(iPathPerfix, list, i, cmdKey);
			auto callBackFunc = [&] {
				auto form = dynamic_cast<MainMenuForm*>(_stackForms->widget(static_cast<int>(SHORT_MENU_FORM_INDEX)));
				form->setElements(buildShortMenu());
				setMenuFormIndex(SHORT_MENU_FORM_INDEX);
				};
			element->setCallBackFunc(callBackFunc);
		}
		break;
		case DIY_SLIDE_MENU_POWER_OFF:
		{
			QList<QString> list;
			QString cmdKey = "POWER_OFF";
			element = new AutoSwitchButton(iPathPerfix, list, i, cmdKey);
		}
		break;
		case DIY_SLIDE_MENU_COLOR_PALETTES:
		{
			QList<QString> list;
			list.push_back(LanguageStr_NS::FALSE_COLOR_WHITE);
			list.push_back(LanguageStr_NS::FALSE_COLOR_BLACK);
			list.push_back(LanguageStr_NS::FALSE_COLOR_REDHOT);
			list.push_back(LanguageStr_NS::FALSE_COLOR_IRONRED);
			list.push_back(LanguageStr_NS::FALSE_COLOR_BLUE);
			list.push_back(LanguageStr_NS::FALSE_COLOR_GREEN);
			list.push_back(LanguageStr_NS::FALSE_COLOR_BROWN);
			QString cmdKey = ns_command_key::colorPalette;
			element = new AutoSwitchButton(iPathPerfix, list, i, cmdKey);
			auto callBackFunc = [&]() {
				// TO DO COMMAND, NEED TO BE IMPLEMENTED
				};
			element->setCallBackFunc(callBackFunc);
		}
		break;
		case DIY_SLIDE_MENU_TAKE_PHOTO:
		{
			QList<QString> list;
			QString cmdKey = "TAKE_PHOTO";
			element = new AutoSwitchButton(iPathPerfix, list, i, cmdKey);
		}
		break;
		case DIY_SLIDE_MENU_ZOOM_OUT:
		{
			QList<QString> list;
			QString cmdKey = "ZOOM_OUT";
			element = new AutoSwitchButton(iPathPerfix, list, i, cmdKey);

		}
		break;
		default:
			break;
		}
		elements.push_back(element);
	}

	return elements;
}

QList<UIElement*> MenuManager::buildMainMenu()
{
	QList<UIElement*> elements;
	QString iPathPerfix = ":/UI/icon/mainMenu";
	UIElement* element = nullptr;
	for (int i = MAIN_MENU_SCREEN_BRI; i <= MAIN_MENU_GENERAL; i++) {
		switch (static_cast<enum MAIN_MENU_INDEX>(i)) {
		case MAIN_MENU_SCREEN_BRI:
		{
			QStringList list;
			for (int i = 1; i <= 5; i++) {
				list.push_back(QString::number(i));
			}
			QString name = LanguageStr_NS::SCREEN_BRIGHTNESS;
			QString cmdKey = ns_command_key::screenBrightness;
			UIElement* dataPtr = nullptr;
			dataPtr = element = new CExpandButton(name, iPathPerfix, i, false, list, cmdKey);
			element->setCallBackFunc(&MenuManager::skipLeafForm, this, dataPtr);
		}
		break;
		case MAIN_MENU_IMAGE_SETTING:
		{
			element = new CSkipButton(LanguageStr_NS::IMAGE_SETTING, iPathPerfix, i);
			auto callback = [this]() {
				this->skipChildsForm(SKIP_IMAGE_SETTING_MENU_INDEX);
				};
			element->setCallBackFunc(callback);
		}
		break;
		case MAIN_MENU_COMPENSATION:
		{
			QString name = LanguageStr_NS::COMPENSATION_MODE;
			QStringList list;
			list.push_back(LanguageStr_NS::AUTO_COMPENSATION);
			list.push_back(LanguageStr_NS::MANUAL_COMPENSATION);
			QString cmdKey = ns_command_key::compensationMethod;
			UIElement* dataPtr = nullptr;
			dataPtr = element = new CExpandButton(name, iPathPerfix, i, false, list, cmdKey);
			element->setCallBackFunc(&MenuManager::skipLeafForm, this, dataPtr);
		}
		break;

		case MAIN_MENU_RETICLE_ZERO:
		{
			element = new CSkipButton(LanguageStr_NS::RETICLE_ZERO, iPathPerfix, i);
			auto callback = [this]() {
				this->skipChildsForm(SKIP_RETICLE_ZERO_MENU_INDEX);
				};
			element->setCallBackFunc(callback);
		}
		break;
		case MAIN_MENU_POWER:
		{
			element = new CSkipButton(LanguageStr_NS::POWER_SETTINGS, iPathPerfix, i);
			auto callback = [this]() {
				this->skipChildsForm(SKIP_POWER_MENU_INDEX);
				};
			element->setCallBackFunc(callback);
		}
		break;
		case MAIN_MENU_RECORD:
		{
			element = new CSkipButton(LanguageStr_NS::RECORD_SETTING, iPathPerfix, i);
			auto callback = [this]() {
				this->skipChildsForm(SKIP_RECORD_MENU_INDEX);
				};
			element->setCallBackFunc(callback);
		}
		break;
		case MAIN_MENU_INDICATION:
		{
			element = new CSwitchButton(LanguageStr_NS::CHARGE_INDICATOR, iPathPerfix, i, ns_command_key::chargeLight);
		}
		break;
		case MAIN_MENU_GENERAL:
		{
			element = new CSkipButton(LanguageStr_NS::GENERAL_SETTINGS, iPathPerfix, i);
			auto callback = [this]() {
				this->skipChildsForm(SKIP_GENERAL_MENU_INDEX);
				};
			element->setCallBackFunc(callback);
		}
		break;
		default:
			break;
		}
		elements.push_back(element);
	}

	return elements;
}

QList<UIElement*> MenuManager::buildShortMenu()
{
	QList<UIElement*> elements;
	QString iPathPerfix = ":/UI/icon/mainMenu";
	UIElement* element = nullptr;
	for (int i = SHORTCUT_MENU_COLOR_PALETTES; i <= SHORTCUT_MENU_DIY; i++) {
		switch (static_cast<enum MAIN_MENU_INDEX>(i)) {
		case SHORTCUT_MENU_COLOR_PALETTES:
		{
			QString name = LanguageStr_NS::FALSE_COLOR;
			QStringList list;
			list.push_back(LanguageStr_NS::FALSE_COLOR_WHITE);
			list.push_back(LanguageStr_NS::FALSE_COLOR_BLACK);
			list.push_back(LanguageStr_NS::FALSE_COLOR_REDHOT);
			list.push_back(LanguageStr_NS::FALSE_COLOR_IRONRED);
			list.push_back(LanguageStr_NS::FALSE_COLOR_BLUE);
			list.push_back(LanguageStr_NS::FALSE_COLOR_GREEN);
			list.push_back(LanguageStr_NS::FALSE_COLOR_BROWN);
			QString cmdKey = ns_command_key::colorPalette;
			UIElement* dataPtr = nullptr;
			dataPtr = element = new CExpandButton(name, iPathPerfix, i, true, list, cmdKey);
			element->setCallBackFunc(&MenuManager::skipLeafForm, this, dataPtr);
		}
		break;
		case SHORTCUT_MENU_ROUGH_RANGING:
		{
			element = new CSkipButton(LanguageStr_NS::IMAGE_SETTING, iPathPerfix, i);
			auto callback = [this]() {
				this->skipChildsForm(SKIP_ROUGH_RANGING_MENU_INDEX);
				};
			element->setCallBackFunc(callback);
		}
		break;
		case SHORTCUT_MENU_TARGET_DISTANCE:
		{
			QString name = LanguageStr_NS::TARGET_DISTANCE;
			QString cmdKey = ns_command_key::zeroingValue;
			QStringList list;
			list.push_back(QString("100"));
			list.push_back(QString("200"));
			UIElement* dataPtr = nullptr;
			dataPtr = element = new CExpandButton(name, iPathPerfix, i, false, list, cmdKey);
			element->setCallBackFunc(&MenuManager::skipLeafForm, this, dataPtr);
		}
		break;
		case SHORTCUT_MENU_WIFI:
		{
			QString name = LanguageStr_NS::WIFI;
			QString cmdKey = ns_command_key::wifiSwitch;
			QStringList list;
			list.push_back(LanguageStr_NS::COMMON_OFF);
			list.push_back(LanguageStr_NS::WIFI_2_4G);
			list.push_back(LanguageStr_NS::WIFI_5G);
			UIElement* dataPtr = nullptr;
			dataPtr = element = new CExpandButton(name, iPathPerfix, i, false, list, cmdKey);
			element->setCallBackFunc(&MenuManager::skipLeafForm, this, dataPtr);
		}
		break;
		case SHORTCUT_MENU_HOT_TRACK:
		{
			element = new CSwitchButton(LanguageStr_NS::HOT_TRACKING, iPathPerfix, i, ns_command_key::hotTracking);
		}
		break;
		case SHORTCUT_MENU_POWER_SAVE:
		{
			element = new CSwitchButton(LanguageStr_NS::POWER_SAVE, iPathPerfix, i, ns_command_key::superSave);
		}
		break;
		case SHORTCUT_MENU_DIY:
		{
			element = new CSkipButton(LanguageStr_NS::DIY_MENU, iPathPerfix, i);
			auto callback = [this]() {
				this->skipChildsForm(SKIP_SHORT_DIY_ADD_MENU);
				};
			element->setCallBackFunc(callback);
		}
		break;
		default:
			break;
		}
		elements.push_back(element);
	}
	return elements;
}

QList<UIElement*> MenuManager::buildImageMenu()
{
	QList<UIElement*> elements;
	UIElement* element = nullptr;
	QString iPathPerfix = ":/UI/icon/mainMenu/imageSetting/";
	for (size_t i = IMAGE_SETTING_SCENE_MODE; i <= IMAGE_SETTING_IMAGE_ENHANCE; i++)
	{
		switch (static_cast<enum IMAGE_SETTING_INDEX>(i)) {
		case IMAGE_SETTING_SCENE_MODE:
		{
			QString name = LanguageStr_NS::SCENE_MODE;
			QString cmdKey = ns_command_key::irSceneMode;
			QStringList list;
			list.push_back(LanguageStr_NS::SCENE_MODE_NORMAL);
			list.push_back(LanguageStr_NS::SCENE_MODE_ENHANCE);
			list.push_back(LanguageStr_NS::SCENE_MODE_LIGHT);
			UIElement* dataPtr = nullptr;
			dataPtr = element = new CExpandButton(name, iPathPerfix, i, true, list, cmdKey);
			element->setCallBackFunc(&MenuManager::skipLeafForm, this, dataPtr);

		}
		break;
		case IMAGE_SETTING_BRIGHTNESS:
		{
			QString name = LanguageStr_NS::IR_BRIGHTNESS;
			QString cmdKey = ns_command_key::brightness;
			QStringList list;
			for (int m = 1; m < 6; m++) {
				list.push_back(QString::number(m));
			}
			UIElement* dataPtr = nullptr;
			dataPtr = element = new CExpandButton(name, iPathPerfix, i, true, list, cmdKey);
			element->setCallBackFunc(&MenuManager::skipLeafForm, this, dataPtr);
		}
		break;
		case IMAGE_SETTING_CONTRAST:
		{
			QString name = LanguageStr_NS::IR_CONTRAST;
			QString cmdKey = ns_command_key::contrast;
			QStringList list;
			for (int m = 1; m < 6; m++) {
				list.push_back(QString::number(m));
			}
			UIElement* dataPtr = nullptr;
			dataPtr = element = new CExpandButton(name, iPathPerfix, i, true, list, cmdKey);
			element->setCallBackFunc(&MenuManager::skipLeafForm, this, dataPtr);
		}
		break;
		case IMAGE_SETTING_IMAGE_ENHANCE:
		{
			element = new CSwitchButton(LanguageStr_NS::IMAGE_ENHANCE, iPathPerfix, i, ns_command_key::imageEnhance);
		}
		break;
		default:
			break;
		}
		elements.push_back(element);
	}
	return elements;
}



QList<UIElement*> MenuManager::buildReticleZeroMenu()
{
	QList<UIElement*> elements;
	UIElement* element = nullptr;
	QString iPathPerfix = ":/UI/icon/mainMenu/Reticle Zero/";
	for (size_t i = RETICLE_ZERO_MENU_MODE; i <= RETICLE_ZERO_MENU_ZERO_SETTING; i++)
	{
		switch (static_cast<enum RETICLE_ZERO_INDEX>(i)) {
		case RETICLE_ZERO_MENU_MODE:
		{
			QString name = LanguageStr_NS::RETICLE_CONFIG;
			QString cmdKey = ns_command_key::reticleConfig;
			QStringList list;
			for (size_t m = 'A'; m < 'F'; m++) {
				list.push_back(QString("%1").arg(char(m)));
			}
			UIElement* dataPtr = nullptr;
			dataPtr = element = new CExpandButton(name, iPathPerfix, i, true, list, cmdKey);
			element->setCallBackFunc(&MenuManager::skipLeafForm, this, dataPtr);

		}
		break;
		case RETICLE_ZERO_MENU_RECTICLE_SETTING:
		{
			element = new CSkipButton(LanguageStr_NS::RETICLE_SETTING, iPathPerfix, i);
			auto callback = [this]() {
				this->skipChildsForm(SKIP_RETICLE_ZERO_RECTICLE_SETTING_MENU_INDEX);
				};
			element->setCallBackFunc(callback);

		}
		break;
		case RETICLE_ZERO_MENU_ZERO_SETTING:
		{
			element = new CSkipButton(LanguageStr_NS::ZERO_SETTING, iPathPerfix, i);
			auto callback = [this]() {
				this->skipChildsForm(SKIP_RETICLE_ZERO_ZERO_SETTING_MENU_INDEX);
				};
			element->setCallBackFunc(callback);
		}
		break;
		default:
			break;
		}
		elements.push_back(element);
	}
	return elements;
}


QList<UIElement*> MenuManager::buildPowerMenu()
{
	QList<UIElement*> elements;
	UIElement* element = nullptr;
	QString iPathPerfix = ":/UI/icon/mainMenu/Pow Setting/";
	for (size_t i = POWER_SETTING_MENU_SMART_SLEEP; i <= POWER_SETTING_MENU_TIMED_OFF_MENU; i++)
	{
		switch (static_cast<enum RETICLE_ZERO_INDEX>(i)) {
		case POWER_SETTING_MENU_SMART_SLEEP:
		{
			element = new CSwitchButton(LanguageStr_NS::SMART_SETTINGS, iPathPerfix, i, ns_command_key::smartSleep);
		}
		break;
		case POWER_SETTING_MENU_TIMED_SHUTDOWN:
		{
			QString name = LanguageStr_NS::TIMED_SHUTDOWN;
			QString cmdKey = ns_command_key::autoShutdown;
			QStringList list;
			list.push_back(QString(LanguageStr_NS::COMMON_OFF));
			list.push_back(QString(LanguageStr_NS::TIME_SET_15MIN));
			list.push_back(QString(LanguageStr_NS::TIME_SET_30MIN));
			list.push_back(QString(LanguageStr_NS::TIME_SET_60MIN));
			UIElement* dataPtr = nullptr;
			dataPtr = element = new CExpandButton(name, iPathPerfix, i, true, list, cmdKey);
			element->setCallBackFunc(&MenuManager::skipLeafForm, this, dataPtr);

		}
		break;
		case POWER_SETTING_MENU_TIMED_OFF_MENU:
		{
			QString name = LanguageStr_NS::AUTO_CLOSE_MENU;
			QString cmdKey = ns_command_key::autoCloseMenu;
			QStringList list;
			list.push_back(QString(LanguageStr_NS::COMMON_OFF));
			list.push_back(QString(LanguageStr_NS::TIME_SET_10SEC));
			list.push_back(QString(LanguageStr_NS::TIME_SET_20SEC));
			list.push_back(QString(LanguageStr_NS::TIME_SET_60SEC));
			UIElement* dataPtr = nullptr;
			dataPtr = element = new CExpandButton(name, iPathPerfix, i, true, list, cmdKey);
			element->setCallBackFunc(&MenuManager::skipLeafForm, this, dataPtr);
		}
		break;
		default:
			break;
		}
		elements.push_back(element);
	}
	return elements;
}

QList<UIElement*> MenuManager::buildRecordMenu()
{
	QList<UIElement*> elements;
	QString iPathPerfix = ":/UI/icon/mainMenu/Record Setting/";
	UIElement* element = nullptr;
	for (size_t i = RECORD_SETTING_MENU_AUDIO; i <= RECORD_SETTING_MENU_WATER_MARK; i++)
	{
		switch (static_cast<enum RETICLE_ZERO_INDEX>(i)) {
		case RECORD_SETTING_MENU_AUDIO:
		{
			element = new CSwitchButton(LanguageStr_NS::AUDIO, iPathPerfix, i, ns_command_key::audioSwitch);
		}
		break;
		case RECORD_SETTING_MENU_VIDEO:
		{
			QString name = LanguageStr_NS::LIMIT_VIDEO;
			QString cmdKey = ns_command_key::timeLimitedRecord;
			QStringList list;
			list.push_back(QString(LanguageStr_NS::COMMON_OFF));
			list.push_back(QString(LanguageStr_NS::TIME_SET_15SEC));
			list.push_back(QString(LanguageStr_NS::TIME_SET_60SEC));
			UIElement* dataPtr = nullptr;
			dataPtr = element = new CExpandButton(name, iPathPerfix, i, true, list, cmdKey);
			element->setCallBackFunc(&MenuManager::skipLeafForm, this, dataPtr);

		}
		break;
		case RECORD_SETTING_MENU_OSD:
		{
			element = new CSwitchButton(LanguageStr_NS::OSD, iPathPerfix, i, ns_command_key::osdSwitch);
		}
		break;
		case RECORD_SETTING_MENU_WATER_MARK:
		{
			element = new CSkipButton(LanguageStr_NS::RECORD_WATER_MODE, iPathPerfix, i);
			auto callback = [this]() {
				this->skipChildsForm(SKIP_RECORD_SETTING_MENU_WATER_MARK_INDEX);
				};
			element->setCallBackFunc(callback);
		}
		break;
		default:
			break;
		}
		elements.push_back(element);
	}

	return elements;
}

QList<UIElement*> MenuManager::buildWaterMenu()
{
	QList<UIElement*> elements;
	QString iPathPerfix = ":/UI/icon/mainMenu/Record Setting/" + QString("s/%1s.png").arg(RECORD_SETTING_MENU_WATER_MARK);
	UIElement* element = nullptr;
	QString name = LanguageStr_NS::RECORD_WATER_MODE;
	for (size_t i = TIME_WATER_MENU_INDEX; i <= LOGO_WATER_MENU_INDEX; i++)
	{
		switch (static_cast<enum WATER_SETTING_MENU_INDEX>(i)) {
		case TIME_WATER_MENU_INDEX:
		{
			element = new SwitchLElement(iPathPerfix, i, name, ns_command_key::timeWatermark);
		}
		break;
		case DATA_WATER_MENU_INDEX:
		{
			element = new SwitchLElement(iPathPerfix, i, name, ns_command_key::dateWatermark);
		}
		break;
		case LOGO_WATER_MENU_INDEX:
		{
			element = new SwitchLElement(iPathPerfix, i, name, ns_command_key::logoWatermark);
		}
		break;
		default:
			break;
		}
		elements.push_back(element);
	}
	return elements;
}

QList<UIElement*> MenuManager::buildGeneralMenu()
{
	QList<UIElement*> list;
	QString iPathPerfix = ":/UI/icon/mainMenu/GeneralSettings/";
	UIElement* element = nullptr;
	for (int i = GENERAL_SETTING_MENU_LANGUAGE; i <= GENERAL_SETTING_MENU_ABOUT; i++) {
		switch (static_cast<enum GENERAL_SETTING_INDEX>(i)) {
		case GENERAL_SETTING_MENU_LANGUAGE:
		{
			QStringList list;
			list.push_back(LanguageStr_NS::LOCAL_LANGUAGE_ENGLISH);
			list.push_back(LanguageStr_NS::LOCAL_LANGUAGE_RUSSIA);
			list.push_back(LanguageStr_NS::LOCAL_LANGUAGE_GERMAN);
			list.push_back(LanguageStr_NS::LOCAL_LANGUAGE_FRENCH);
			//list.push_back(LanguageStr_NS::LOCAL_LANGUAGE_CHINESE);
			list.push_back(LanguageStr_NS::LOCAL_LANGUAGE_ITALIAN);
			list.push_back(LanguageStr_NS::LOCAL_LANGUAGE_SPANISH);
			//languageList.push_back(LanguageStr_NS::LOCAL_LANGUAGE_JAPANESE);
			//languageList.push_back(LanguageStr_NS::LOCAL_LANGUAGE_KOREAN);
			//languageList.push_back(LanguageStr_NS::LOCAL_LANGUAGE_POLAND);
			list.push_back(LanguageStr_NS::LOCAL_LANGUAGE_ROMANIAN);
			list.push_back(LanguageStr_NS::LOCAL_LANGUAGE_NORWEGIAN);
			list.push_back(LanguageStr_NS::LOCAL_LANGUAGE_SWEDISH);
			list.push_back(LanguageStr_NS::LOCAL_LANGUAGE_DANISH);
			list.push_back(LanguageStr_NS::LOCAL_LANGUAGE_CZECH);
			list.push_back(LanguageStr_NS::LOCAL_LANGUAGE_SLOVAK);
			list.push_back(LanguageStr_NS::LOCAL_LANGUAGE_HUNGARIAN);
			list.push_back(LanguageStr_NS::LOCAL_LANGUAGE_FINNISH);
			QString name = LanguageStr_NS::LOCAL_LANGUAGE;
			QString cmdKey = ns_command_key::languageSetting;
			UIElement* dataPtr = nullptr;
			dataPtr = element = new CExpandButton(name, iPathPerfix, i, false, list, cmdKey);
			element->setCallBackFunc(&MenuManager::skipLeafForm, this, dataPtr);
		}
		break;
		case GENERAL_SETTING_MENU_UNIT:
		{
			QStringList list;
			list.push_back(LanguageStr_NS::UNIT_M);
			list.push_back(LanguageStr_NS::UNIT_YD);
			QString name = LanguageStr_NS::UNIT_SETTING;
			QString cmdKey = ns_command_key::unitSetting;
			UIElement* dataPtr = nullptr;
			dataPtr = element = new CExpandButton(name, iPathPerfix, i, false, list, cmdKey);
			element->setCallBackFunc(&MenuManager::skipLeafForm, this, dataPtr);
		}
		break;
		case GENERAL_SETTING_MENU_DATE_TIME:
		{
			element = new CSkipButton(LanguageStr_NS::DATE_AND_TIME, iPathPerfix, i);
			auto callback = [this]() {
				this->skipChildsForm(SKIP_GENERAL_SETTING_DATA_TIME);
				};
			element->setCallBackFunc(callback);
		}
		break;
		case GENERAL_SETTING_MENU_OFF_SCREEN_DISPLAY:
		{

			element = new CSwitchButton(LanguageStr_NS::ALWAYS_DISPLAY, iPathPerfix, i, ns_command_key::offScreenDisplay);
		}
		break;
		case GENERAL_SETTING_MENU_BLUETOOTH:
		{
			element = new CSwitchButton(LanguageStr_NS::BLUETOOTH, iPathPerfix, i, ns_command_key::bluetoothSwitch);
		}
		break;
		case GENERAL_SETTING_MENU_FORMAT:
		{
			element = new CSkipButton(LanguageStr_NS::LOCAL_MEMORY_FORMAT, iPathPerfix, i);
			auto callback = [this]() {
				//this->skipChildsForm(SKIP_GENERAL_SETTING_MENU_FORMAT);
				//to Do Command   ns_command_key::memoryCardFormat
				};
			element->setCallBackFunc(callback);
		}
		break;
		case GENERAL_SETTING_MENU_RESTORE_DEFAULT:
		{
			element = new CSkipButton(LanguageStr_NS::LOCAL_RESET, iPathPerfix, i);
			auto callback = [this]() {
				//this->skipChildsForm(SKIP_GENERAL_SETTING_RESTORE_DEFAULT);

				//to Do Command  ns_command_key::restoreDefaults
				};
			element->setCallBackFunc(callback);
		}
		break;
		case GENERAL_SETTING_MENU_ABOUT:
		{
			element = new CSkipButton(LanguageStr_NS::LOCAL_ABOUT, iPathPerfix, i);
			auto callback = [this]() {
				this->skipChildsForm(SKIP_GENERAL_SETTING_ABOUT);
				};
			element->setCallBackFunc(callback);
		}
		break;
		default:
			break;
		}
		list.push_back(element);
	}

	return list;
}

int MenuManager::menuFormIndex() const
{
	int currentIndex = _stackForms->currentIndex() < SECOND_MENU_FORM_INDEX ? SHORT_MENU_FORM_INDEX : _stackForms->currentIndex();
	currentIndex++;
	if (currentIndex < LEAF_MENU_FORM_INDEX) {
		return currentIndex;
	}
	return -1;
}

void MenuManager::skipDiyFunc(const int& index)
{


}

void MenuManager::skipLeafForm(UIElement* dataPtr)
{
	if (dataPtr == nullptr)
	{
		return;
	}
	auto form = dynamic_cast<LeafForm*>(_stackForms->widget(static_cast<int>(LEAF_MENU_FORM_INDEX)));
	disconnect(0, &QTimer::timeout, form, 0);
	form->setElements(dynamic_cast<CExpandButton*>(dataPtr)->convertToElements());
	form->setName(dynamic_cast<CExpandButton*>(dataPtr)->name());
	setMenuFormIndex(LEAF_MENU_FORM_INDEX);
}

void MenuManager::skipChildsForm(const int index)
{
	switch (static_cast<enum SKIP_MENU_FORM_INDEX>(index))
	{
	case SKIP_IMAGE_SETTING_MENU_INDEX:
	{
		int currentIndex = menuFormIndex();
		if (currentIndex < 0) {
			return;
		}
		auto form = dynamic_cast<SecondMenuForm*>(_stackForms->widget(currentIndex));
		form->setElements(buildImageMenu());
		form->setName(LanguageStr_NS::IMAGE_SETTING);
		setMenuFormIndex(currentIndex);

	}
	break;
	case SKIP_RETICLE_ZERO_MENU_INDEX:
	{
		int currentIndex = menuFormIndex();
		if (currentIndex < 0) {
			return;
		}
		auto form = dynamic_cast<SecondMenuForm*>(_stackForms->widget(static_cast<int>(currentIndex)));
		form->setElements(buildReticleZeroMenu());
		form->setName(LanguageStr_NS::RETICLE_ZERO);
		setMenuFormIndex(currentIndex);
	}
	break;

	case SKIP_POWER_MENU_INDEX:
	{
		int currentIndex = menuFormIndex();
		if (currentIndex < 0) {
			return;
		}
		auto form = dynamic_cast<SecondMenuForm*>(_stackForms->widget(static_cast<int>(currentIndex)));
		form->setElements(buildPowerMenu());
		form->setName(LanguageStr_NS::POWER_SETTINGS);
		setMenuFormIndex(currentIndex);
	}
	break;
	case SKIP_RECORD_MENU_INDEX:
	{
		int currentIndex = menuFormIndex();
		if (currentIndex < 0) {
			return;
		}
		auto form = dynamic_cast<SecondMenuForm*>(_stackForms->widget(static_cast<int>(currentIndex)));
		form->setElements(buildRecordMenu());
		form->setName(LanguageStr_NS::RECORD_SETTING);
		setMenuFormIndex(currentIndex);
	}
	break;
	case SKIP_GENERAL_MENU_INDEX:
	{
		int currentIndex = menuFormIndex();
		if (currentIndex < 0) {
			return;
		}
		auto form = dynamic_cast<SecondMenuForm*>(_stackForms->widget(static_cast<int>(currentIndex)));
		form->setElements(buildGeneralMenu());
		form->setName(LanguageStr_NS::GENERAL_SETTINGS);
		setMenuFormIndex(currentIndex);
	}
	break;
	case SKIP_ROUGH_RANGING_MENU_INDEX:
	{

	}
	break;
	case SKIP_RETICLE_ZERO_RECTICLE_SETTING_MENU_INDEX:
	{

	}
	break;
	case SKIP_RETICLE_ZERO_ZERO_SETTING_MENU_INDEX:
	{

	}
	break;
	case SKIP_RECORD_SETTING_MENU_WATER_MARK_INDEX:
	{
		auto form = dynamic_cast<LeafForm*>(_stackForms->widget(static_cast<int>(LEAF_MENU_FORM_INDEX)));
		disconnect(0, &QTimer::timeout, form, 0);
		form->setElements(buildWaterMenu());
		form->setName(LanguageStr_NS::RECORD_WATER_MODE);
		setMenuFormIndex(LEAF_MENU_FORM_INDEX);
	}
	break;
	case SKIP_GENERAL_SETTING_DATA_TIME:
	{

	}
	break;
	case SKIP_GENERAL_SETTING_MENU_FORMAT:
	{

	}
	break;
	case SKIP_GENERAL_SETTING_RESTORE_DEFAULT:
	{

	}
	break;
	case SKIP_GENERAL_SETTING_ABOUT:
	{

	}
	break;
	default:
		break;
	}


}

void MenuManager::addMenuForm(ElementForm* form)
{
	if (form == nullptr) {
		return;
	}
	_stackForms->addWidget(form);
	connect(form, &ElementForm::sglGoBackBtnClicked, this, &MenuManager::slotGoBackBtnClicked);
}

void MenuManager::slotGoBackBtnClicked(ElementForm* form) {
	if (_stackForms->indexOf(form) != -1) {
		_stackForms->setCurrentWidget(form);
	}
}

void MenuManager::left()
{
	if (_isLongPress) {
		return;
	}
	CHECK_FORM(left);
}

void MenuManager::right()
{
	if (_isLongPress) {
		return;
	}
	CHECK_FORM(right);
}

void MenuManager::repeat()
{

	CHECK_FORM(repeat);
}

void MenuManager::finish()
{
	if (_isLongPress) {
		_isLongPress = false;
	}
	CHECK_FORM(finish);
}

void MenuManager::shortPress()
{
	CHECK_FORM(shortPress);
}

void MenuManager::longPress()
{
	_isLongPress = true;
	CHECK_FORM(longPress);
}